package com.example.score.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.score.entity.SubmitStatistics;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SubmitStatisticsMapper extends BaseMapper<SubmitStatistics> {
    
    /**
     * 批量插入提交统计
     */
    void insertBatch(@Param("list") List<SubmitStatistics> list);

    /**
     * 查询年级在指定日期的提交统计
     */
    @Select("<script>SELECT * FROM t_submit_statistics " +
            "WHERE grade_info_id in " +
            "<foreach collection='gradeIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach></script>")
    SubmitStatistics selectByGradeAndDate(
            @Param("gradeIds") List<Long> gradeIds,
            @Param("subjectId") Long subjectId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime);

    /**
     * 查询班级在指定日期的提交统计
     */
    @Select("SELECT * FROM t_submit_statistics " +
            "WHERE class_id = #{classId} " +
            "AND subject_id = #{subjectId} " +
            "AND statistics_date BETWEEN #{startTime} AND #{endTime} " +
            "ORDER BY statistics_date DESC LIMIT 1")
    SubmitStatistics selectByClassAndDate(
            @Param("classId") Long classId,
            @Param("subjectId") Long subjectId,
            @Param("startTime") LocalDateTime startTime,
            @Param("endTime") LocalDateTime endTime);

    @Select("<script>select * from t_submit_statistics " +
            "where class_id in" +
            "<foreach collection='classIds' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach> </script>")
    List<SubmitStatistics> selectListByClassIds(@Param("classIds") List<Long> classIds);

    @Select("select * from t_submit_statistics where exam_detail_id =#{id} ")
    List<SubmitStatistics> selectByExamDetailId(Long id);
}